#!/usr/bin/env python
import wsgiref.handlers
import os

from google.appengine.ext import webapp
from google.appengine.api import users
from google.appengine.ext.webapp import template

class MainPage(webapp.RequestHandler):
  def get(self):
    user = users.get_current_user()
    self.response.headers['Content-Type'] = 'text/html'
    if user:
      nickname = user.nickname()
    else:
      #self.redirect(users.create_login_url(self.request.uri))
      nickname = 'guest'
    template_values = {'nickname' : nickname }
    path = os.path.join(os.path.dirname(__file__), 'index.html')
    self.response.out.write(template.render(path, template_values))
    
def main():
  application = webapp.WSGIApplication(
                                       [('/', MainPage)],
                                       debug=True)
  wsgiref.handlers.CGIHandler().run(application)

if __name__ == "__main__":
  main()

